package smap;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import BD.AlunoBD;
import DAO.AlunoDAO;
import BD.AtividadesBD;
import DAO.AtividadesDAO;

public class TelaAluno extends javax.swing.JDialog {
    
    AlunoDAO aluDao = new AlunoDAO();
    AtividadesDAO atDao = new AtividadesDAO();
    AlunoBD alu = new AlunoBD();
    AtividadesBD at = new AtividadesBD();

    public TelaAluno(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grupoAluno = new javax.swing.ButtonGroup();
        pnlPrincipal = new javax.swing.JPanel();
        btnProfessor = new javax.swing.JButton();
        btnUsuario = new javax.swing.JButton();
        btnCurso = new javax.swing.JButton();
        btnDisciplina = new javax.swing.JButton();
        btnAluno = new javax.swing.JButton();
        btnBackup = new javax.swing.JButton();
        btnTurma = new javax.swing.JButton();
        pnlVoltar = new javax.swing.JPanel();
        btnVoltar = new javax.swing.JButton();
        pnlControle = new javax.swing.JPanel();
        txtPesquisaAluno = new javax.swing.JTextField();
        cmbPesquisa = new javax.swing.JComboBox();
        btnPesquisar = new javax.swing.JButton();
        btnCarregartodos = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnCadastrar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAluno = new javax.swing.JTable();
        btnAdicionarTese = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Tela Aluno");
        setResizable(false);

        pnlPrincipal.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(192, 192, 192)));

        btnProfessor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/professor-icon.png"))); // NOI18N
        btnProfessor.setText("Professor");
        btnProfessor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProfessorActionPerformed(evt);
            }
        });

        btnUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/user-icon.png"))); // NOI18N
        btnUsuario.setText("Usuario");
        btnUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUsuarioActionPerformed(evt);
            }
        });

        btnCurso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/curso-icon.png"))); // NOI18N
        btnCurso.setText("Curso");
        btnCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCursoActionPerformed(evt);
            }
        });

        btnDisciplina.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/disciplina-icon.png"))); // NOI18N
        btnDisciplina.setText("Disciplina");
        btnDisciplina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDisciplinaActionPerformed(evt);
            }
        });

        btnAluno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/aluno-icon.png"))); // NOI18N
        btnAluno.setText("Aluno");
        btnAluno.setEnabled(false);

        btnBackup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/backup-icon.png"))); // NOI18N
        btnBackup.setText("Backup");
        btnBackup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackupActionPerformed(evt);
            }
        });

        btnTurma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/turma-icon.png"))); // NOI18N
        btnTurma.setText("Turma");
        btnTurma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTurmaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlPrincipalLayout = new javax.swing.GroupLayout(pnlPrincipal);
        pnlPrincipal.setLayout(pnlPrincipalLayout);
        pnlPrincipalLayout.setHorizontalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnProfessor, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnTurma, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnBackup, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlPrincipalLayout.setVerticalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnProfessor)
                    .addComponent(btnUsuario)
                    .addComponent(btnAluno)
                    .addComponent(btnBackup)
                    .addComponent(btnDisciplina)
                    .addComponent(btnCurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnTurma))
                .addContainerGap())
        );

        pnlVoltar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(192, 192, 192)));

        btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/voltar-icon.png"))); // NOI18N
        btnVoltar.setText("Voltar");
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlVoltarLayout = new javax.swing.GroupLayout(pnlVoltar);
        pnlVoltar.setLayout(pnlVoltarLayout);
        pnlVoltarLayout.setHorizontalGroup(
            pnlVoltarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlVoltarLayout.createSequentialGroup()
                .addGap(522, 522, 522)
                .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlVoltarLayout.setVerticalGroup(
            pnlVoltarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlVoltarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlControle.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(192, 192, 192)), "Pesquisar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12), java.awt.Color.darkGray)); // NOI18N

        cmbPesquisa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RA", "Nome", "CPF", "Bolsista", "Ano de ingresso", "Orientador", "Curso" }));

        btnPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/procurar-icon.png"))); // NOI18N
        btnPesquisar.setText("Pesquisar");
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        btnCarregartodos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/todos-icon.png"))); // NOI18N
        btnCarregartodos.setText("Carregar todos");
        btnCarregartodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCarregartodosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlControleLayout = new javax.swing.GroupLayout(pnlControle);
        pnlControle.setLayout(pnlControleLayout);
        pnlControleLayout.setHorizontalGroup(
            pnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlControleLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cmbPesquisa, 0, 153, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtPesquisaAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 675, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCarregartodos, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnlControleLayout.setVerticalGroup(
            pnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlControleLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPesquisaAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisar)
                    .addComponent(btnCarregartodos))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/delete-icon.png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/alterar-icon.png"))); // NOI18N
        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        btnCadastrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/add-icon.png"))); // NOI18N
        btnCadastrar.setText("Cadastrar");
        btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarActionPerformed(evt);
            }
        });

        tblAluno.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(192, 192, 192)));
        tblAluno.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "RA", "Sexo", "Nome", "CPF", "Telefone", "Celular", "Bolsista", "Ingresso", "Email", "Orientador", "Curso", "cod_prof", "cod_curso"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblAluno.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblAluno.getTableHeader().setResizingAllowed(false);
        tblAluno.getTableHeader().setReorderingAllowed(false);
        tblAluno.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblAlunoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblAluno);
        tblAluno.getColumnModel().getColumn(0).setMinWidth(80);
        tblAluno.getColumnModel().getColumn(0).setPreferredWidth(60);
        tblAluno.getColumnModel().getColumn(0).setMaxWidth(80);
        tblAluno.getColumnModel().getColumn(1).setMinWidth(0);
        tblAluno.getColumnModel().getColumn(1).setPreferredWidth(0);
        tblAluno.getColumnModel().getColumn(1).setMaxWidth(0);
        tblAluno.getColumnModel().getColumn(3).setMinWidth(120);
        tblAluno.getColumnModel().getColumn(3).setPreferredWidth(100);
        tblAluno.getColumnModel().getColumn(3).setMaxWidth(120);
        tblAluno.getColumnModel().getColumn(4).setMinWidth(120);
        tblAluno.getColumnModel().getColumn(4).setPreferredWidth(120);
        tblAluno.getColumnModel().getColumn(4).setMaxWidth(145);
        tblAluno.getColumnModel().getColumn(5).setMinWidth(0);
        tblAluno.getColumnModel().getColumn(5).setPreferredWidth(0);
        tblAluno.getColumnModel().getColumn(5).setMaxWidth(0);
        tblAluno.getColumnModel().getColumn(6).setMinWidth(0);
        tblAluno.getColumnModel().getColumn(6).setPreferredWidth(0);
        tblAluno.getColumnModel().getColumn(6).setMaxWidth(0);
        tblAluno.getColumnModel().getColumn(7).setMinWidth(90);
        tblAluno.getColumnModel().getColumn(7).setPreferredWidth(90);
        tblAluno.getColumnModel().getColumn(7).setMaxWidth(110);
        tblAluno.getColumnModel().getColumn(8).setMinWidth(0);
        tblAluno.getColumnModel().getColumn(8).setPreferredWidth(0);
        tblAluno.getColumnModel().getColumn(8).setMaxWidth(0);
        tblAluno.getColumnModel().getColumn(11).setMinWidth(0);
        tblAluno.getColumnModel().getColumn(11).setPreferredWidth(0);
        tblAluno.getColumnModel().getColumn(11).setMaxWidth(0);
        tblAluno.getColumnModel().getColumn(12).setMinWidth(0);
        tblAluno.getColumnModel().getColumn(12).setPreferredWidth(0);
        tblAluno.getColumnModel().getColumn(12).setMaxWidth(0);

        btnAdicionarTese.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/tese-icon.png"))); // NOI18N
        btnAdicionarTese.setText("Adicionar Tese");
        btnAdicionarTese.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionarTeseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addComponent(pnlControle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlVoltar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnAdicionarTese, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(226, 226, 226)
                .addComponent(btnCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlControle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExcluir)
                    .addComponent(btnAlterar)
                    .addComponent(btnCadastrar)
                    .addComponent(btnAdicionarTese))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void btnProfessorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProfessorActionPerformed
        this.dispose(); // Fecha Tela Aluno
        TelaProfessor pro = new TelaProfessor(null, true);
        pro.carregarTabela("");
        pro.setVisible(true); // Abre Tela Professor
    }//GEN-LAST:event_btnProfessorActionPerformed

    private void btnUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUsuarioActionPerformed
        this.dispose();  // Fecha Tela Aluno
        TelaUsuario usu = new TelaUsuario(null, true);
        usu.carregarTabela("");
        usu.setVisible(true); //Abre Tela Usuario
    }//GEN-LAST:event_btnUsuarioActionPerformed

    private void btnCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCursoActionPerformed
        this.dispose(); // Fecha Tela Aluno
        TelaCurso cur = new TelaCurso(null, true);
        cur.carregarTabela("");
        cur.setVisible(true); // Abre Tela Curso
    }//GEN-LAST:event_btnCursoActionPerformed

    private void btnDisciplinaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisciplinaActionPerformed
        this.dispose(); // Fecha Tela Aluno
        TelaDisciplina dis = new TelaDisciplina(null, true);
        dis.carregarTabela("");
        dis.setVisible(true); // Abre Tela Disciplina
    }//GEN-LAST:event_btnDisciplinaActionPerformed

    private void btnBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackupActionPerformed
        this.dispose(); // Fecha Tela Principal
        TelaBackup bac = new TelaBackup(null, true);
        bac.setVisible(true); // Abre Tela Backup
    }//GEN-LAST:event_btnBackupActionPerformed

    private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
        this.dispose(); // Fecha Tela Aluno
    }//GEN-LAST:event_btnVoltarActionPerformed

    private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarActionPerformed
        TelaCadAluno cadalu = new TelaCadAluno (null, true);
        cadalu.carregarComboCurso(); //carregar combo do curso
        cadalu.carregarComboProfessor(); //carregar combo do professor
        cadalu.setCadastrar(true); //true = habilita para cadastrar
        cadalu.setVisible(true); //Abre Tela Cadastrar Aluno
        carregarTabela(txtPesquisaAluno.getText().trim());
    }//GEN-LAST:event_btnCadastrarActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        if(tblAluno.getSelectedRow() == -1){ // Não selecionou nenhuma Linha
            JOptionPane.showMessageDialog(null,"Selecione um aluno para alterar", "Selecione o aluno", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {          
            //Obtem os dados de acordo com a linha ao qual foi selecionada.
            Integer linha = tblAluno.getSelectedRow();

            //Seta os valores do aluno, para transferi-lo para próxima tela.    
            alu.setRa((Integer)tblAluno.getValueAt(linha, 0));
            alu.setSexo((String)tblAluno.getValueAt(linha, 1));
            alu.setNome((String)tblAluno.getValueAt(linha, 2));
            alu.setCpf((String)tblAluno.getValueAt(linha, 3));
            alu.setTelefone((String)tblAluno.getValueAt(linha, 4));
            alu.setCelular((String)tblAluno.getValueAt(linha, 5));
            alu.setBolsista((String)tblAluno.getValueAt(linha, 6));
            alu.setDataIngresso((String)tblAluno.getValueAt(linha, 7));
            alu.setEmail((String)tblAluno.getValueAt(linha, 8));
            alu.setNomeProfessorAux((String)tblAluno.getValueAt(linha, 9));
            alu.setNomeCursoAux((String)tblAluno.getValueAt(linha, 10));
            
            //Campo escondido na jTable
            alu.setCodProfessor((Integer)tblAluno.getValueAt(linha, 11));
            alu.setCodCurso((Integer)tblAluno.getValueAt(linha, 12));
            
            //lista para armazenar o resultado da pesquisa por codigo
            List<AlunoBD> listaAluno = new ArrayList<AlunoBD>();
            
            //Converter o codigo para String, para passar ao método filtro.
            String campo = Integer.toString(alu.getRa());
            
            //Armazenar o aluno referente ao codigo selecionado para capturarmos os documentos
            listaAluno = aluDao.filtro("ra_al", campo);
                        
            //Para o Aluno encontrado, setar o "valor" dos documentos.
            for(AlunoBD al : listaAluno){ 
                alu.setDocRG(al.getDocRG());
                alu.setDocCPF(al.getDocCPF());
                alu.setDocCertidao(al.getDocCertidao());
                alu.setDocTitulo(al.getDocTitulo());
                alu.setDocCurriculum(al.getDocCurriculum());
                alu.setDocFoto(al.getDocFoto());
                alu.setDocCarta(al.getDocCarta());
                alu.setDocHistorico(al.getDocHistorico());
                alu.setDocDiploma(al.getDocDiploma());
                alu.setDocCertificado(al.getDocCertificado());
                alu.setPossuiOutrosDocumentos(al.getPossuiOutrosDocumentos());
                alu.setOutrosDocsEntregues(al.getOutrosDocsEntregues());
                alu.setObservacoes(al.getObservacoes());
            }
                        
            //Manda os dados para a tela de Alterar
            this.enable();
            TelaCadAluno altalu = new TelaCadAluno(null, true);
            altalu.carregarComboProfessor();
            altalu.carregarComboCurso();
            altalu.setCadastrar(false); //false = habilita para alterar
            altalu.recebeObjeto(alu);
            altalu.setVisible(true);
            carregarTabela(txtPesquisaAluno.getText().trim());
        }   
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        if(tblAluno.getSelectedRow() == -1){ // Não selecionou nenhuma Linha
            JOptionPane.showMessageDialog(null,"Selecione um aluno para excluir", "Selecione o aluno", JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            Object[] opcoes = { "Sim", "Não" };
             //Obtem os dados de acordo com a linha ao qual foi selecionada.
            Integer linha = tblAluno.getSelectedRow();
            Integer resposta =JOptionPane.showOptionDialog(null,"Deseja excluir este aluno ?", "Exclusão",JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null,
                    opcoes, opcoes[1]);
            
            // Verifica Resposta do Usuário
            if(resposta == JOptionPane.OK_OPTION){
                //seta o Ra do aluno
                alu.setRa((Integer)tblAluno.getValueAt(linha, 0));
                atDao.verificaExclusaoAtividade((String.valueOf(tblAluno.getValueAt(linha,0))),"Documentos Faltantes");
                atDao.verificaExclusaoAtividade((String.valueOf(tblAluno.getValueAt(linha,0))),"Creditos faltantes");

                //excluir
                if(aluDao.excluirAluno(alu)){
                   
                    JOptionPane.showMessageDialog(null,"Exclusão Realizada com Sucesso", 
                        "Excluir", JOptionPane.INFORMATION_MESSAGE);
                    //recarregar o jTable
                    carregarTabela("");
                }
                else{
                    JOptionPane.showMessageDialog(null,"Nao foi possível realizar a exclusão", 
                        "Excluir", JOptionPane.INFORMATION_MESSAGE);
                }
            }
            else{
                JOptionPane.showMessageDialog(null,"Exclusão cancelada", "Exclusão", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
        //lista os alunos de acordo com o que foi digitado
        carregarTabela(txtPesquisaAluno.getText().trim());
    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnCarregartodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCarregartodosActionPerformed
        //lista todos os alunos
        carregarTabela("");
    }//GEN-LAST:event_btnCarregartodosActionPerformed

    private void tblAlunoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAlunoMouseClicked
        if(evt.getClickCount() == 2){
            if(tblAluno.getSelectedRow() == -1){ // Não selecionou nenhuma Linha
                JOptionPane.showMessageDialog(null,"Selecione um aluno para visualizar", "Selecione o aluno", JOptionPane.INFORMATION_MESSAGE);
            }
            else
            {   
                //Obtem os dados de acordo com a linha ao qual foi selecionada.
                Integer linha = tblAluno.getSelectedRow();

                //Seta os valores do aluno, para transferi-lo para próxima tela.    
                alu.setRa((Integer)tblAluno.getValueAt(linha, 0));
                alu.setSexo((String)tblAluno.getValueAt(linha, 1));
                alu.setNome((String)tblAluno.getValueAt(linha, 2));
                alu.setCpf((String)tblAluno.getValueAt(linha, 3));
                alu.setTelefone((String)tblAluno.getValueAt(linha, 4));
                alu.setCelular((String)tblAluno.getValueAt(linha, 5));
                alu.setBolsista((String)tblAluno.getValueAt(linha, 6));
                alu.setDataIngresso((String)tblAluno.getValueAt(linha, 7));
                alu.setEmail((String)tblAluno.getValueAt(linha, 8));
                alu.setNomeProfessorAux((String)tblAluno.getValueAt(linha, 9));
                alu.setNomeCursoAux((String)tblAluno.getValueAt(linha, 10));
                
                //campo escondido na jtable
                alu.setCodProfessor((Integer)tblAluno.getValueAt(linha, 11));
                alu.setCodCurso((Integer)tblAluno.getValueAt(linha, 12));
                
                //lista para armazenar o resultado da pesquisa por codigo
                List<AlunoBD> listaAluno = new ArrayList<AlunoBD>();

                //Converter o codigo para String, para passar ao método filtro.
                String campo = Integer.toString(alu.getRa());

                //Armazenar o aluno referente ao ra selecionado para capturarmos os documentos
                listaAluno = aluDao.filtro("ra_al", campo);

                //Para o Aluno encontrado, setar o "valor" dos documentos.
                for(AlunoBD al : listaAluno){ 
                    alu.setDocRG(al.getDocRG());
                    alu.setDocCPF(al.getDocCPF());
                    alu.setDocCertidao(al.getDocCertidao());
                    alu.setDocTitulo(al.getDocTitulo());
                    alu.setDocCurriculum(al.getDocCurriculum());
                    alu.setDocFoto(al.getDocFoto());
                    alu.setDocCarta(al.getDocCarta());
                    alu.setDocHistorico(al.getDocHistorico());
                    alu.setDocDiploma(al.getDocDiploma());
                    alu.setDocCertificado(al.getDocCertificado()); 
                    alu.setPossuiOutrosDocumentos(al.getPossuiOutrosDocumentos());
                    alu.setOutrosDocsEntregues(al.getOutrosDocsEntregues());
                    alu.setObservacoes(al.getObservacoes());
                    
                }

                //Manda os dados para a tela de Alterar
                this.enable();
                TelaCadAluno altalu = new TelaCadAluno(null, true);
                altalu.carregarComboCurso();
                altalu.carregarComboProfessor();
                altalu.visualizaObjeto(alu);
                altalu.setTitle("Visualizar aluno");
                altalu.setVisible(true);
            }
        }
    }//GEN-LAST:event_tblAlunoMouseClicked

    private void btnTurmaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTurmaActionPerformed
        this.dispose(); // Fecha Tela Aluno
        TelaTurma tur = new TelaTurma(null, true);
        tur.carregarTabela("");
        tur.setVisible(true); // Abre Tela Turma
    }//GEN-LAST:event_btnTurmaActionPerformed

    private void btnAdicionarTeseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarTeseActionPerformed
        this.setEnabled(false);
        TelaCadTese cadtes = new TelaCadTese(null, true);
        cadtes.carregarComboLinhaPesq(); //carregar combo com linhas de pesquisa
        cadtes.carregarComboCurso(); //carregar combo do curso
        cadtes.autoIncremento(); //carregar auto incremento pro código
        cadtes.carregarTabela(""); //carregar tabela de teses cadastradas
        cadtes.setVisible(true); //abrir tela
        this.setEnabled(true);
        this.show();
    }//GEN-LAST:event_btnAdicionarTeseActionPerformed

    public void carregarTabela(String campo){
        List<AlunoBD> listaAluno = new ArrayList<AlunoBD>(); 
        
        //Verifica qual radio button esta selecionado para fazer a pesquisa
        if(cmbPesquisa.getSelectedIndex()== 0){
            listaAluno = aluDao.filtro("a.ra_al", campo);
        }
        else{
            if(cmbPesquisa.getSelectedIndex()== 1){
                listaAluno = aluDao.filtro("a.nome_al", campo);
            }else{
                if(cmbPesquisa.getSelectedIndex()== 2){
                    listaAluno = aluDao.filtro("a.cpf_al", campo);
                }else{
                    if(cmbPesquisa.getSelectedIndex()== 3){
                        listaAluno = aluDao.filtro("a.bolsista_al", campo);
                    }else{
                        if(cmbPesquisa.getSelectedIndex()== 4){
                            listaAluno = aluDao.filtro("a.dataingresso_al", campo);
                        }else{
                            if(cmbPesquisa.getSelectedIndex() == 5){
                                listaAluno = aluDao.filtro("p.nome_prof", campo);    
                            }else{
                                listaAluno = aluDao.filtro("c.nome_curso", campo);    
                            }
                        }
                    }
                }
            }
        }
        //define um modelo para a Jtable
        DefaultTableModel tbm = (DefaultTableModel)tblAluno.getModel();         
        
        //Remove as linhas da Jtable, para limpar.
        for(int i = tbm.getRowCount()-1; i >= 0; i--){ 
            tbm.removeRow(i); 
        } 
        int i = 0; 
        
        //Para cada aluno que ele encontrar, adiciona uma nova linha na Jtable
        for(AlunoBD al : listaAluno){            
            tbm.addRow(new String[1]); 
            tblAluno.setValueAt(al.getRa(), i, 0);
            tblAluno.setValueAt(al.getSexo(), i, 1);
            tblAluno.setValueAt(al.getNome(), i, 2); 
            tblAluno.setValueAt(al.getCpf(), i, 3); 
            tblAluno.setValueAt(al.getTelefone(), i, 4);
            tblAluno.setValueAt(al.getCelular(),i, 5);
            tblAluno.setValueAt(al.getBolsista(),i, 6);
            tblAluno.setValueAt(al.getDataIngresso(),i,7);
            tblAluno.setValueAt(al.getEmail(),i,8);
            tblAluno.setValueAt(al.getNomeProfessorAux(),i,9);
            tblAluno.setValueAt(al.getNomeCursoAux(),i,10);      
            tblAluno.setValueAt(al.getCodProfessor(),i,11);
            tblAluno.setValueAt(al.getCodCurso(),i,12);
            i++; 
        }
        centralizarTable();
    }
    
     public void centralizarTable(){
        //Centralizar os dados na tabela.
        DefaultTableCellRenderer center = new DefaultTableCellRenderer();
        center.setHorizontalAlignment(SwingConstants.CENTER ); 
        tblAluno.getColumnModel().getColumn(0).setCellRenderer(center);
        tblAluno.getColumnModel().getColumn(1).setCellRenderer(center);
        tblAluno.getColumnModel().getColumn(3).setCellRenderer(center);
        tblAluno.getColumnModel().getColumn(4).setCellRenderer(center);
        tblAluno.getColumnModel().getColumn(5).setCellRenderer(center);
        tblAluno.getColumnModel().getColumn(6).setCellRenderer(center);
    }
    
    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaAluno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                TelaAluno dialog = new TelaAluno(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdicionarTese;
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnAluno;
    private javax.swing.JButton btnBackup;
    private javax.swing.JButton btnCadastrar;
    private javax.swing.JButton btnCarregartodos;
    private javax.swing.JButton btnCurso;
    private javax.swing.JButton btnDisciplina;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JButton btnProfessor;
    private javax.swing.JButton btnTurma;
    private javax.swing.JButton btnUsuario;
    private javax.swing.JButton btnVoltar;
    private javax.swing.JComboBox cmbPesquisa;
    private javax.swing.ButtonGroup grupoAluno;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnlControle;
    private javax.swing.JPanel pnlPrincipal;
    private javax.swing.JPanel pnlVoltar;
    private javax.swing.JTable tblAluno;
    private javax.swing.JTextField txtPesquisaAluno;
    // End of variables declaration//GEN-END:variables
}
